#include <gflags/gflags.h>

#include "es.hpp"

DEFINE_bool(run_mode, true, "是否为调试模式");
DEFINE_string(log_file, "", "发布模式下，用于指定日志的输出文件");
DEFINE_int32(log_level, 0, "发布模式下，用于指定日志输出等级");

DEFINE_string(es_host, "http://127.0.0.1:9200/", "es服务器URL");

int main(int argc, char *argv[])
{
    google::ParseCommandLineFlags(&argc, &argv, true);
    im::initLogger(FLAGS_run_mode, FLAGS_log_file, FLAGS_log_level);

    // auto db = im::ODBFactory::create("root", "123456", "127.0.0.1", "im", "utf8", 0, 1);

    auto es_client = im::ESClientFactory::create({FLAGS_es_host});

    im::ESUser es_user = im::ESUser(es_client);

    es_user.createIndex();

    // es_user.appendData("用户ID1", "手机号1", "小猪佩奇", "这是一只小猪", "小猪头像1");
    // es_user.appendData("用户ID2", "手机号2", "小猪乔治", "这是一只小小猪", "小猪头像2");
    
    std::vector<std::string> user_names{"爸爸", "妈妈", "小张", "小兰"};
    std::vector<std::string> user_phones{"11111111111", "12222222222", "13333333333", "14444444444"};
    std::vector<std::string> user_descriptions{"父亲", "母亲", "儿子", "女儿"};
    std::vector<std::string> user_avatars_id{"9686-d64b0e21-0000", "1fee-42622dd1-0001", "ded5-0fccd7eb-0002", "8bfc-bd6bed34-0003"};
    for(int i = 0; i < 4; i++){
        es_user.appendData(std::to_string(i+1), user_phones[i], user_names[i], user_descriptions[i], user_avatars_id[i]);
    }

    std::vector<std::string> filter({"用户ID1"});
    auto result = es_user.search("小猪", filter);
    for (auto &u : result) {
        std::cout << "-----------------" << std::endl;
        std::cout << u.user_id() << std::endl;
        std::cout << u.phone() << std::endl;
        std::cout << u.user_name() << std::endl;
        std::cout << u.description() << std::endl;
        std::cout << u.avatar_id() << std::endl;
    }
    return 0;
}